package com.ruoyi.customer.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.customer.mapper.CustomerLinkmaneMapper;
import com.ruoyi.customer.domain.CustomerLinkmane;
import com.ruoyi.customer.service.ICustomerLinkmaneService;

/**
 * 客户联系人Service业务层处理
 *
 * @author aef
 * @date 2022-11-27
 */
@Service
public class CustomerLinkmaneServiceImpl extends ServiceImpl<CustomerLinkmaneMapper, CustomerLinkmane> implements ICustomerLinkmaneService {

    /**
     * 查询客户联系人列表
     *
     * @param customerLinkmane 客户联系人
     * @return 客户联系人
     */
    @Override
    public List<CustomerLinkmane> selectCustomerLinkmaneList(CustomerLinkmane customerLinkmane) {
        return getBaseMapper().selectCustomerLinkmaneList(customerLinkmane);
    }

    @Override
    public boolean saveOrUpdate(CustomerLinkmane customerLinkmane){
        if (customerLinkmane.getAge() < 0 || customerLinkmane.getAge() > 100){
            throw new ServiceException("年龄异常");
        }
        if (customerLinkmane.getId() == null){
            customerLinkmane.setInputUser(SecurityUtils.getUsername());
            customerLinkmane.setInputTime(new Date());
            if(customerLinkmane.getPositionState() == 1){
                throw new ServiceException("新增时任职状态只能为在职！");
            }
            customerLinkmane.setPositionState(0);
            return super.save(customerLinkmane);
        }else {
            return super.updateById(customerLinkmane);
        }
    }

    @Override
    public List<CustomerLinkmane> selevtByCustomerId(Long customerId) {
        List<CustomerLinkmane> customerLinkmaneList = getBaseMapper().selectByCustomerId(customerId);
        return customerLinkmaneList;
    }


}
